package com.imddysc.jzknavigator.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.imddysc.jzknavigator.service.ZknavigatorService;

@Controller
public class ZknavigatorEditsubController {
	
	private static final Logger logger = LoggerFactory.getLogger(ZknavigatorEditsubController.class);
	
	@Autowired
	private ZknavigatorService zknavigatorService;

	@RequestMapping(value = "/editsub", method=RequestMethod.POST)
	public ModelAndView editsub(String node, String content) {
		ModelAndView mav = new ModelAndView();
		logger.info("editsub: ");
		logger.info("node: " + node);
		logger.info("content: " + content);
		
		String path1 = node.replace("|","/");
		String path2 = path1.replace("//","/");
		
		try {
			zknavigatorService.putData(path2, content);
			mav.addObject("message", "修改保存数据成功，请查看数据是否保存成功！");
		} catch (Exception e) {
			logger.error("修改保存数据异常，请查看核实数据是否保存成功！");
			mav.addObject("message", "修改保存数据异常，请查看核实数据是否保存成功！");
			e.printStackTrace();
		}
		
		mav.addObject("last_url", node);
		mav.setViewName("editsub");
		return mav;
	}

}
